const koa = require("koa")
const app = new koa();
const router = require("koa-router")()
// const main = require("./models")
const koaBody = require("koa-body")
const path = require("path");
const fs = require("fs");
const static = require("koa-static");
router.get("/",async ctx=>{
    ctx.body = "连接成功"
})
router.post("/file", async ctx => {
    console.log(ctx.request.body);
    console.log(ctx.request.files.logo.path);
    var logo = ctx.request.files.logo.path;
    var reader = fs.createReadStream(logo);
    var uploadFile = `./static/${path.basename(logo)}`;
    var write = fs.createWriteStream(uploadFile);
    reader.pipe(write);
    console.log(ctx.origin);//获取主机ip
    console.log(ctx.origin+"/"+path.basename(logo));//存入数据库完整路径
    ctx.body = "上传成功"
})
app.use(koaBody({
    multipart: true,
    formidable: {
        maxFileSize: 200 * 1024 * 1024,    
		keepExtensions: true
    }
}))
app.use(router.routes());
app.use(static(path.join(__dirname,"static")))

app.listen(7000)